package com.medsoft.drpcp;

import io.netty.channel.Channel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GlobalConfig {
	public static String nodeName;
	public static boolean isServer;
	public static int port;
	public static int timeout;
	public static boolean compress = false;
	public static boolean isDynamicRouteEnable = false;
	public static List<RouteItem> routeItems = new ArrayList<RouteItem>();
	public static boolean encrypt = false;
	
	private static Map<String,Server> servers = new HashMap<String,Server>();
	public static int backlog;
	/** 业务处理线程大小*/  
    public static int busiThreadCount;
	public static boolean isCloud = false;
	
	public static Map<String,Server> getServers() {
		return servers;
	}
	
	public static void addServer(String nodeName,int connSize) {
		servers.put(nodeName,new Server(nodeName,connSize));
	}
	
	public static void addServer(Server server) {
		servers.put(server.getNodeName(),server);
	}
	
	public static Server getServer(String nodeName) {
		return servers.get(nodeName);
	}
	
	public static Channel getRandomMember(String nodeName) {
		return servers.get(nodeName).getRandomMember();
	}
	
	public static void removeMember(String serverName,String address,int port) {
		servers.get(serverName).removeMember(address, port);
		if(servers.get(serverName).getMemberSize() == 0) {
			servers.get(serverName).setDisconnected(true);
		}
	}
	
	public static void addMember(String serverName,String address,int port) {
		servers.get(serverName).addMember(address, port);
		servers.get(serverName).setDisconnected(false);
	}
}
